package cn.edu.ctbu.scoremg.dao;

import cn.edu.ctbu.scoremg.entity.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TeacherRepository extends JpaRepository<Teacher,Integer> {
    /**
     * 按名字进行查询
     * @param name
     * @return
     */
    List<Teacher> findByNameLike(String name);
    /**
     * 按名字和工号进行查询
     * @param name
     * @param tno
     * @return
     */
    List<Teacher> findByNameAndTno(String name,String tno);
    List<Teacher> findByTno(String tno);

    /*@Query("select t from tb_teacher t where substring(t,tno,1,4) ="+
            "(select substring(MAX(t1,tno),1,4)from tb_teacher t1 group by substring(t1,tno,1,4)having count(*)>1)")
    List<Teacher> findLastTeacherWithSamePrefix();*/
    @Modifying
    @Query("delete from tb_teacher s where s.id in :ids")
    void deleteByIds(List<Integer> ids);
}
